#pragma once
#include<iostream>
#include<string>

using namespace std;
string opers="+-*/%";//集中存储合法的运算符,通过find接口快速检查

enum{
    DivZero=1,
    ModZero,
    Unknown
};

class Task
{
public:
    Task(int x,int y,char c)
    :data1(x),data2(y),op(c),result(0),exitcode(0)
    {}
    void run()
    {
        switch(op)
        {
            case '+':
                result=data1+data2;
                break;
            case '-':
                result=data1-data2;
                break;
            case '*':
                result=data1*data2;
                break;
            case '/':
                {
                    if(data2==0) exitcode=DivZero;
                    else result=data1/data2;
                }
                break;
            case '%':
                {
                    if(data2==0) exitcode=ModZero;
                    else result=data1%data2;
                }
                break;
            default:
                exitcode=Unknown;
                break;
        }
    }

    void operator()()//函数重载，让类的对象可以像函数一样被调用
    {
        run();
    }
    string GetResult()
    {
         string r=to_string(data1);
         r+=op;
         r+=to_string(data2);
         r+='=';
         r+=to_string(result);
         r+="[code:]";
         r+=to_string(exitcode);
         r+=']';
         return r;
    }

    string GetTask()
    {
        string r=to_string(data1);
        r+=op;
        r+=to_string(data2);
        r+="=?";
        return r;
    }
    ~Task()
    {
    }
private:
    int data1;
    int data2;
    char op;
    int result;
    int exitcode;
};